import { DisposeView } from "../../../mvc/core/DisposeView";
import { PageTool } from "../../../common/global/PageTool";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { LadderBattlefieldGuardRenderer } from "./renderer/LadderBattlefieldGuardRenderer";
import { Language } from "../../../../extend/language/Language";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { GTileList } from "../../../../com/mui/controls/GTileList";
//class LadderBattlefieldGuardView
    
    export  class LadderBattlefieldGuardView extends DisposeView
    {
        constructor()
        {
            super();
            this._pageTool = new PageTool([], 9);
            return;
        }

        /* internal  */onInputTxtChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            if (int(this._inputTxt.text) > this._pageSelecter.maxPage) 
            {
                this._inputTxt.text = this._pageSelecter.maxPage.toString();
            }
            return;
        }

        /* internal  */onClickReturnBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._pageSelecter.currentPage = int(this._inputTxt.text);
            this.drawList();
            return;
        }

        /* internal  */onClickRefreshBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.LadderBattlefieldGetBattles));
            return;
        }

        /* internal  */onListPageChange(arg1: Object /* flash.events.Event */=null): void
        {
            this.drawList();
            return;
        }

        /* internal  */drawList(): void
        {
            this._list.dataProvider = new DataProvider(this._pageTool.getByPageNo(this._pageSelecter.currentPage));
            this._list.drawNow();
            return;
        }

        public set battlefieldList(arg1: Array<any>)
        {
            this._pageTool.array = arg1;
            this._pageSelecter.currentPage = this._pageTool.currentPage;
            this._pageSelecter.maxPage = this._pageTool.pagesCount;
            this.drawList();
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            pushUIToDisposeVec(ObjCreate.createBg(0, 0, 425, 325, this));
            pushUIToDisposeVec(ObjCreate.createBg(-1, -3, 430, 32, this, ImagesConst.RbListHeader));
            this._pageSelecter = ObjCreate.createPageSelecter(95, 338, this);
            this._pageSelecter.mode = PageSelecter.CompleteMode;
            this._pageSelecter.configEventListener(flash.events.Event.CHANGE, this.onListPageChange);
            if (!this._list) 
            {
                this._list = ObjCreate.createTileList(0, 30, 425, 290);
                this._list.scrollPolicy = ScrollPolicy.OFF;
                this._list.columnWidth = 425;
                this._list.rowHeight = 32;
                this._list.setStyle("cellRenderer", LadderBattlefieldGuardRenderer);
            }
            this.addChild(this._list);
            this._inputTxt = ObjCreate.createGTextInput(255, 339, 63, 20, this);
            this._inputTxt.restrict = "0-9";
            this._inputTxt.configEventListener(flash.events.Event.CHANGE, this.onInputTxtChangeHandler);
            pushUIToDisposeVec(ObjCreate.createGButton(Language.getString(28591), 340, 338, 42, 20, this, "Button", this.onClickReturnBtnHandler));
            pushUIToDisposeVec(ObjCreate.createGButton(Language.getString(28608), 48, 338, 42, 20, this, "Button", this.onClickRefreshBtnHandler));
            var loc1=GlobalStyle.setTextFormatAlign(GlobalStyle._textFormat2, flash.text.TextFormatAlign.CENTER);
            pushUIToDisposeVec(ObjCreate.createGTextFiledBitmap(Language.getString(28822), 0, 5, 170, 20, this, loc1));
            pushUIToDisposeVec(ObjCreate.createGTextFiledBitmap(Language.getString(28823), 170, 5, 30, 20, this, loc1));
            pushUIToDisposeVec(ObjCreate.createGTextFiledBitmap(Language.getString(28822), 200, 5, 170, 20, this, loc1));
            pushUIToDisposeVec(ObjCreate.createGTextFiledBitmap(Language.getString(28824), 380, 5, 30, 20, this, loc1));
            pushUIToDisposeVec(ObjCreate.createGTextFiledBitmap(Language.getString(28604), 225, 338, 150, 20, this, GlobalStyle._textFormat2));
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            this._inputTxt.dispose(arg1);
            this._pageSelecter.dispose(arg1);
            this._inputTxt = null;
            this._pageSelecter = null;
            return;
        }

        /* internal */ /* var */_inputTxt: GTextInput;

        /* internal */ /* var */_list: GTileList;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_pageTool: PageTool;
    }
